Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

484
Visualizações
Comparing text element with "%" sign like a number and seeing if a number is greaterThan 0 does not work
describe('dropdown select', () => {
  it('open dropdown and check if 24hr rate is positive', () => {
    Cypress.on('uncaught:exception', (err, runnable) => {return false}) //it was throwing expections for me for unknown reason so I had to ignore it
    cy.visit('link')
    cy.get('[data-cy=accept-btn]').click() 
    cy.get('#currency-select').should('be.visible').click() 
    cy.get('[class=" css-zkvt1b-menu"]').should('be.visible').contains('EUR').click()
    cy.get('[class="Yq Zq"]').each((el) => {
        const text = el.text();
        expect(text).to.be.greaterThan(0);
    })

  });
})  

I am getting error checking of the number is greaterThan 0. Adding a picture of the error below: NOTE: the numbers are different in screenshots because they were taken few minutes apart.

enter image description here

Chrome code:

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You have to extract the number and remove the extra strings and then convert it into a number and then apply assertions.

cy.visit('https://spectrocoin.com/en/bitcoin-price-rates.html')
Cypress.on('uncaught:exception', (err, runnable) => {
  return false
})
cy.get('[data-cy=accept-btn]').click()
cy.get('#currency-select').should('be.visible').click()
cy.get('[class=" css-zkvt1b-menu"]')
  .should('be.visible')
  .contains('EUR')
  .click()
cy.get('[data-cy="rates"] tr').each((el) => {
  cy.wrap(el).within(() => {
    cy.get('td')
      .eq(2)
      .invoke('text')
      .then((text) => {
        const last24HourVal = +text.slice(13, -1)
        expect(last24HourVal).to.be.greaterThan(0)
      })
  })
})

The above test will fail for values which are less than 0. To check whether the number can be positive or negative you have to use a conditional statement and check for the value to be greater or less than 0 and then apply assertion. Something like:

cy.visit('https://spectrocoin.com/en/bitcoin-price-rates.html')
Cypress.on('uncaught:exception', (err, runnable) => {
  return false
})
cy.get('[data-cy=accept-btn]').click()
cy.get('#currency-select').should('be.visible').click()
cy.get('[class=" css-zkvt1b-menu"]')
  .should('be.visible')
  .contains('EUR')
  .click()
cy.get('[data-cy="rates"] tr').each((el) => {
  cy.wrap(el).within(() => {
    cy.get('td')
      .eq(2)
      .invoke('text')
      .then((text) => {
        const last24HourVal = +text.slice(13, -1)
        if (last24HourVal > 0) {
          expect(last24HourVal).to.be.greaterThan(0)
        } else {
          expect(last24HourVal).to.be.lessThan(0)
        }
      })
  })
})
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda